<template>
    <div>
        <title-bar title="详情"></title-bar>
        <div class="detail">
            <div class="activity-info" v-if='item'>
               <detail-panel :item='item' :user='userType' ></detail-panel>
        </div>
    </div>
</template>
<script>
import { PostServiceClass } from '../../services/post.js'
import VueRouter from 'vue-router'
import TitleBar from '../components/TitleBar'
import { SLOTH_TOKEN, ActiveForUser } from "../../const"
import DetailPanel from '../components/Detail/DetailPanel'
import moment from 'moment'

const post = new PostServiceClass()

export default {
    components: {
        TitleBar,
        DetailPanel
    },
    data() {
        return {
            item:'',
            userId:'',
            userType: ActiveForUser.UnLogin,
            recruit:false
        }
    },
    route: {
        activate(){
                this.item = ''
        },
        data({ to: { params: { postId } }}){
            window.scrollTo(0,0)
            this.getItem(postId)
        }
    },
    methods: {
        async getItem(postId) {
            let data = await post.GetAsync(postId)
            this.item = data
            if(data.type === 2 || data.type ===3){
                this.setUserType(data)
            }
        },
        setUserType(data) {
            console.log(data)
            if (!data.current) {
                this.userType = ActiveForUser.UnLogin
            } else {
                this.userType = data.current.avtiveForUser
                if (this.userType === ActiveForUser.Normal) {
                    if(moment().isAfter(moment.utc(data.teamTimeRange.end).local()) || (this.data.members.length == this.data.teamMemberMaxCount))
                    this.userType = ActiveForUser.End
                }
            }
        }
    }
}


</script>
<style lang='sass'>
    @import '../../vendor/styles/detail.scss';
</style>
